//=============================================================================
// XBus 
//-----------------------------------------------------------------------------
// File        : xbus.h
// Description : XBus version file
// Author      : Ismail Sabry
// Date        : 1/30/2009
//=============================================================================
#ifndef __XBUS_H__
#define __XBUS_H__

#include <version.h>

//-----------------------------------------------------------------------------
// MAGICTAG & TAG
// identification des zone/module/cell Xbus
//-----------------------------------------------------------------------------
#define XBUS_MAGICTAG_XBUS         0xC0DECAFE
#define XBUS_MAGICTAG_MODULE       0xC0DEDEDE
#define XBUS_MAGICTAG_CELL         0xC0DECE11

typedef  unsigned long t_XBUS_magictag;

//-----------------------------------------------------------------------------
// Taille Path 
//-----------------------------------------------------------------------------
#define XBUS_MAX_SIZE              512000000 // 512MBytes

//-----------------------------------------------------------------------------
// limit
//-----------------------------------------------------------------------------
#define XBUS_MIN_NB_MODULE         1
#define XBUS_MAX_NB_MODULE         1000

#define XBUS_MIN_NB_CELL           2         // par Module
#define XBUS_MAX_NB_CELL           1000      // par Module

#define XBUS_MIN_SIZE_CELL         32        // 32 Bytes
#define XBUS_MAX_SIZE_CELL         10240000  // 10 MBytes

//-----------------------------------------------------------------------------
// Cell
//-----------------------------------------------------------------------------

typedef struct {
  t_XBUS_magictag          magictag;
  int                      next; // offset (bytes)  to next
  unsigned int             len;
} t_XBUS_cell_header;

typedef struct {
  t_XBUS_cell_header       head;
  unsigned char            body;
} t_XBUS_cell;

//-----------------------------------------------------------------------------
// Video module
//-----------------------------------------------------------------------------
typedef struct {
  t_XBUS_magictag          magictag;
  unsigned int             witer;   // write iteration
  unsigned int             wcell;   // wrtie cell (index)
} t_XBUS_module_header;

typedef struct {
  t_XBUS_module_header     head;
  t_XBUS_cell              cell;
} t_XBUS_module;


//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
#define XBUS_NIM_SIZE_NAME      4
#define XBUS_MAX_SIZE_NAME      16

#define XBUS_SIZE_NAME          (XBUS_MAX_SIZE_NAME)

typedef struct {
  t_XBUS_magictag          magictag;
  t_XBUS_version           version; 
  char                     name[XBUS_SIZE_NAME];
  unsigned int             nb_module;
  unsigned int             nb_cell;
  unsigned int             size_cell;
  unsigned int             size; // shm size
} t_XBUS_header;

typedef struct {
  t_XBUS_header            head;
  t_XBUS_module            module;
} t_XBUS;

#endif // __XBUS_H__
